public class text11 {
    public static void main(String[] args) {
        Object qiu=new Object();
        Object pai=new Object();
        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (qiu)
                {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (pai)
                    {
                        System.out.println("小明把球和球拍都拿到了");
                    }

                }

        }


        });
        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (pai)
                {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    synchronized (qiu)
                    {
                        System.out.println("小张把球和球拍都拿到了");
                    }
                }


            }
        });
        thread1.start();
        thread2.start();


    }
}
